package com.iweb.test0809;

import javax.servlet.*;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

/**
 * ClassName: HelloListener
 * Package: com.iweb.test0809
 * Description:
 *
 * @Author Jerry
 * @Create 2024/8/9 9:33
 * @Version 1.0
 */
public class HelloListener implements ServletContextListener, HttpSessionListener, ServletRequestListener {
    @Override
    public void contextInitialized(ServletContextEvent sce) {
        ServletContext sc=sce.getServletContext();
        sc.setAttribute("myApplicationKey","myApplicationValue");
        System.out.println("context被创建");
    }

    @Override
    public void contextDestroyed(ServletContextEvent sce) {
        ServletContext sc=sce.getServletContext();
        System.out.println(sc.getAttribute("myApplicationKey"));
        System.out.println("context被销毁");
    }

    @Override
    public void requestDestroyed(ServletRequestEvent sre) {
        System.out.println("请求被销毁");
    }

    @Override
    public void requestInitialized(ServletRequestEvent sre) {
        System.out.println("请求被创建");
    }

    @Override
    public void sessionCreated(HttpSessionEvent se) {
        System.out.println("会话被创建");
    }

    @Override
    public void sessionDestroyed(HttpSessionEvent se) {
        System.out.println("会话被销毁");
    }
}
